package com.dhcc.DRGsHosp.web.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dayatang.utils.Page;
import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.facade.MiMonthProPortionFacade;
import com.dhcc.DRGsHosp.facade.dto.MiMonthProPortionDTO;
import com.dhcc.DRGsHosp.facade.dto.ParamMap;

@Controller("drgsHospWebController28")
@RequestMapping("/MiMonthProPortion")
public class MiMonthProPortionController {
		
	@Autowired
	private MiMonthProPortionFacade miMonthProPortionFacade;
	
	@ResponseBody
	@RequestMapping("/add")
	public InvokeResult add(MiMonthProPortionDTO miMonthProPortionDTO) {
		return miMonthProPortionFacade.creatMiMonthProPortion(miMonthProPortionDTO);
	}
	
	@ResponseBody
	@RequestMapping("/update")
	public InvokeResult update(MiMonthProPortionDTO miMonthProPortionDTO) {
		return miMonthProPortionFacade.updateMiMonthProPortion(miMonthProPortionDTO);
	}
	
	@ResponseBody
	@RequestMapping("/pageJson")
	public Page pageJson(MiMonthProPortionDTO miMonthProPortionDTO, @RequestParam int page, @RequestParam int pagesize) {
		Page<MiMonthProPortionDTO> all = miMonthProPortionFacade.pageQueryMiMonthProPortion(miMonthProPortionDTO, page, pagesize);
		return all;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public InvokeResult remove(@RequestParam String mimpMonths) {
		String[] value = mimpMonths.split(",");
        String[] idArrs = new String[value.length];
        for (int i = 0; i < value.length; i ++) {
        					idArrs[i] = value[i];
			        				        }
        return miMonthProPortionFacade.removeMiMonthProPortions(idArrs);
	}
	
	@ResponseBody
	@RequestMapping("/get/{mimpMonth}")
	public InvokeResult get(@PathVariable String mimpMonth) {
		return miMonthProPortionFacade.getMiMonthProPortion(mimpMonth);
	}
	
	@ResponseBody
	@RequestMapping("/findAllMiMonthProPortion")
	public List<MiMonthProPortionDTO> findAllMiMonthProPortion() {
		return miMonthProPortionFacade.findAllMiMonthProPortion();
	}
	
	
	/**
	 * @methodname :selectMiMonthProByType
	 * @Description : 根据基金类型查询查询基金的所有年份每个月的分配比例
	 * @author:yujiaolong
	 * @return InvokeResult
	 * @date :2017年6月22日
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMiMonthProByType")
	//String icdVersion, String icdType,
	public InvokeResult selectMiMonthProByType(HttpServletRequest request, HttpServletResponse response) {		  
		Map<String,Object> map=new ParamMap().newMap(request);
		return miMonthProPortionFacade.selectMiMonthProByType(map);
	}
	
	
	/**
	 * @methodname :addMonthProporByType
	 * @Description : 保存和更新基金的所有年份每个月的分配比例
	 * @author:yujiaolong
	 * @return InvokeResult
	 * @date :2017年6月23日
	 */
	@ResponseBody
	@RequestMapping(value = "/addMonthProporByType")
	//String icdVersion, String icdType,
	public InvokeResult addMonthProporByType(HttpServletRequest request, HttpServletResponse response) {		  
		Map<String,Object> map=new ParamMap().newMap(request);
		return miMonthProPortionFacade.addMonthProporByType(map);
		
	}
	
	
	/**
	 * @methodname :getFundByType
	 * @Description : 根据年份获取基金总额
	 * @author:yujiaolong
	 * @return InvokeResult
	 * @date :2017年6月27日
	 */
	@ResponseBody
	@RequestMapping(value = "/getFundByType")
	//String icdVersion, String icdType,
	public InvokeResult getFundByType(HttpServletRequest request, HttpServletResponse response) {		  
		Map<String,Object> map=new ParamMap().newMap(request);
		return miMonthProPortionFacade.getFundByType(map);
		
	}
	
	

	/**
	 * 
	 * @methodname    :addMonthProportion
	 * @description   :保存医保总额
	 * @param         :
	 * @author        :yujiaolong
	 * @return        :
	 * @date          :2017年6月23日
	 */
	@ResponseBody
	@RequestMapping("/addHCTotalFundByType"  )  
    public InvokeResult addHCTotalFundByType(HttpServletRequest request, HttpServletResponse response){
		Map<String,Object> map= new ParamMap().newMap(request);
		miMonthProPortionFacade.addHCTotalFundByType(map);
		return InvokeResult.success();
	}
		
    @InitBinder    
    public void initBinder(WebDataBinder binder) {  
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");    
        dateFormat.setLenient(false);    
        //CustomDateEditor 可以换成自己定义的编辑器。
        //注册一个Date 类型的绑定器 。
        binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
	
}
